/*
 * Copyright 2021-2030 itbox.cn All right reserved. This software is the confidential and proprietary information
 * of itbox.cn ("Confidential Information"). You shall not disclose such Confidential Information and shall use it
 * only in accordance with the terms of the license agreement you entered into with itbox.cn.
 */
package cn.itbox.example.test.config;

import org.apache.commons.codec.Resources;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.stereotype.Component;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @BelongProject uap
 * @BelongPackage cn.itbox.example.test.config
 * @Description TODO
 * @ClassName MyEnvironmentPostProcessor
 * @Author xingc
 * @Date 2024/1/21 6:06
 * @Version 1.0.0
 */

@Component
public class MyEnvironmentPostProcessor implements EnvironmentPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        try {
            //InputStream inputStream = new FileInputStream("E:\\uap\\springboot-study\\springboot-study-test\\src\\main\\resources\\jdbc.properties");
            InputStream inputStream = Resources.getInputStream("jdbc.properties");
            Properties properties = new Properties();
            properties.load(inputStream);
            PropertiesPropertySource propertiesPropertySource = new PropertiesPropertySource("my", properties);
            environment.getPropertySources().addLast(propertiesPropertySource);

            //JasyptPreparedEnvListener listener = new JasyptPreparedEnvListener();
            //listener.refresh(environment);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

